package newsDB;

import java.util.List;

import newsEntity.Topic;

public class TopicDao extends BaseDao {
	public static final TopicDao td = new TopicDao();

	public List<Topic> findTopic() {
		String sql = "select * from topic group by `tid`";
		return find(sql, Topic.class);
	}

	public int addTopic(String tname) {
		String sql = "INSERT INTO `topic`(tname) VALUES(?)";
		return executeUpdate(sql, tname);
	}

	public int changeTopic(Long tid, String tname) {
		String sql = "UPDATE `topic` SET `tname`=? WHERE tid=?";
		return executeUpdate(sql, tname, tid);
	}

	public boolean topicisExise(String tname) {
		String sql = "select `tid` from topic where tname=?";
		List<Topic> list = find(sql, Topic.class, tname);
		if (list != null && list.size() > 0) {
			return true;
		}
		return false;
	}
}
